<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

		<title>接口测试平台 - 登录</title>
		<link href="./css/style_log.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" type="text/css" href="./css/style.css">
	</head>

	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script src="js/config.js" type="application/javascript"></script>

	<body class="login" mycollectionplug="bind">
		<div class="login_m">
			<!-- <div class="login_logo"><img src="./images/logo.png" width="196" height="46"></div> -->
			<div class="login_boder">

				<div class="login_padding" id="login_model">
					<form method="post" class="layui-form">
						<h2>USERNAME</h2>
						<label>
							<input type="text" id="username" name="username" placeholder="用户名" required class="txt_input txt_input2" type="text" lay-verify="required">
						</label>
						<h2>PASSWORD</h2>
						<label>
							<input type="password" name="password" id="userpwd" placeholder="密码" class="txt_input">
						</label>

						<div class="rem_sub">
							<label>
								<input type="submit" lay-submit lay-filter="login" class="sub_button" name="button" id="login" value="登录" style="opacity: 0.7; margin-top: 15px;">
							</label>
						</div>
					</form>
				</div>




				<!--login_padding  Sign up end-->
			</div>
			<!--login_boder end-->
		</div>
		<!--login_m end-->
		<script>
			$(function() {
				layui.use('form', function() {
					var form = layui.form;
					form.on('submit(login)', function(data) {
						$.ajax({
							url: base_url + '/user/login',
							type: 'post',
							contentType: 'application/json; charset=utf-8',
							data: JSON.stringify(data.field),
							dataType: 'json',
							async: false,
							success: function(result) {
								if (result.code == '0') {
									username = $("#username").val();
									var token = result.data[0].randuid;
									$.ajax({
										url: base_url + '/project/list',
										type: 'get',
										data: {},
										dataType: 'json',
										success: function(result) {
											if (result.code == '0' && result.count > 0) {
												projectname = result.data[0].projectname;
												projectid = result.data[0].id;
												location.replace('index.html#/username=' + username + "|" + token + "#/projectname=" +
													projectname + "#/projectid=" + projectid);
											} else {
												if (username == "admin") {
													alert("没有参加任何项目，请添加项目")
													location.replace("addproject.html#/username=admin|350956#");
												} else {
													layer.msg("没有参加任何项目");
												}
											}
										}
									});
								} else {
									layer.msg(result.msg);
								}
							}
						});
						return false;
					});
				});
			})
		</script>


	</body>
</html>
